package com.zipking.cloud.springbootmybatis.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import com.zipking.cloud.springbootmybatis.config.Async;
import com.zipking.cloud.springbootmybatis.model.TaskWrapper;
import com.zipking.cloud.springbootmybatis.persistance.entity.MsgLog;
import com.zipking.cloud.springbootmybatis.persistance.mapper.MsgLogMapper;
import com.zipking.cloud.springbootmybatis.service.IMsgLogService;
import com.zipking.cloud.springbootmybatis.service.ITask;
import com.zipking.cloud.springbootmybatis.util.SpringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
@Slf4j
public class QueryUsersTask implements ITask<MsgLog> {
    @Autowired
    private IMsgLogService msgLogService;
    @Autowired
    private MsgLogMapper msgLogMapper;

    @Override
    public void run(TaskWrapper<MsgLog> taskWrapper) {

//            List<User> list = new ArrayList<>();
//            for (int i = 0; i < 100; i++) {
//                User user = new User();
//                list.add(user);
//            }
        try{
            LambdaQueryWrapper<MsgLog> queryWrapper = new LambdaQueryWrapper<MsgLog>();
            queryWrapper.eq(MsgLog::getRoutingKey,"XX").last("limit 10000");
            List<MsgLog> msgLogList = msgLogMapper.selectList(queryWrapper);
            log.info("========"+msgLogList.size());
            OperatorTask operatorTask = SpringUtils.getBean(OperatorTask.class);
            taskWrapper.setTaskList(msgLogList);
            Async.startPoolInSingleThread(operatorTask,taskWrapper);
        }catch (Exception e){
            Map<String, Object> map = new HashMap<>();
            map.put("errorMsg",e.getMessage());
            //usersMapper.insertTransLog(map);
        }

    }
}